package com.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.project.bean.BuyerCarBean;
import com.project.bean.ProductBean;
import com.project.bean.UserBean;
import com.project.service.IBuyCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("buyCar")
public class BuyCarController {
    @Autowired
    private IBuyCarService buyCarService;
    @RequestMapping("add")
    public String add(String option, ProductBean product, Integer unm, HttpServletRequest req, Integer money) {
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        buyCarService.add(option, product, unm, user.getId(), money);
        return "ok";
    }

    @RequestMapping("del")
    public String del(Integer buyCarId) {
        buyCarService.del(buyCarId);
        return "ok";
    }

    @RequestMapping("update")
    public String updateNum(Integer buyCarId, Integer num) {
        buyCarService.updateNum(buyCarId, num);
        return "ok";
    }

    @RequestMapping("findByUserId")
    public List<BuyerCarBean> findByUserId(HttpServletRequest req) {
        UserBean user = (UserBean)req.getSession().getAttribute("loginUser");
        return buyCarService.findByUserId(user.getId());
    }
}
